﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EasyStep.Business.Interfaces;
using EasyStep.Website.Models;

namespace EasyStep.Website.Controllers
{
    [Authorize]
    public class TestConstsController : Controller
    {
        private ITestConstantsListManager ConstsList { get; set; }
        private ITestConstantManager Consts { get; set; }
        private ITestProjectManager Projects { get; set; }
        private ITestUserManager Users { get; set; }
        
        public TestConstsController(ITestConstantManager tConst,ITestConstantsListManager tConstList, ITestProjectManager tProjects, ITestUserManager tUsers)
        {
            this.Consts= tConst;
            this.Projects = tProjects;
            this.Users = tUsers;
            this.ConstsList = tConstList; 
        }


        /// <summary>
        /// here we are showing list of available projects and their constant lists 
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            var model = Projects.GetUserProjects(Users.Current().Id);
                model.ToList().ForEach(p=>
                {
                    p.ConstantLists = ConstsList.GetProjectConstList(p.Id); 
                });
            return View(model);
        }

        public ActionResult Details(int id)
        {
            return View();
        }

        public ActionResult Create()
        {
            //var model = new TestConstListCreateModel()
            //{ 
            //    ConstListNameOrId = "default",
            //    Name="new constant name"
            //};
            return View();
        }

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /TestConsts/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /TestConsts/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /TestConsts/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /TestConsts/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        
    }
}
